//
// Created by Semir on 2020/6/10.
//

#include <iostream>
#include "../Util/Tree.h"

using namespace std;

TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {
    if (root == nullptr) {
        return nullptr;
    }
    int min = std::min(p->val, q->val);
    int max = std::max(p->val, q->val);
    if (root->val >= min && root->val <= max) {
        return root;
    } else if (root->val < min) {
        return lowestCommonAncestor(root->right, p, q);
    } else {
        return lowestCommonAncestor(root->left, p, q);
    }
}

int main() {
    return 0;
}